package com.apimarket.entity.kong;

import com.fasterxml.jackson.annotation.JsonProperty;

import javax.validation.constraints.NotNull;
import java.util.Date;
import java.util.List;
import java.util.Map;

public class Plugin {
    private String id;

    @NotNull(message = "插件名不能为空")
    private String name;
    @JsonProperty("created_at")
    private Date createdAt;

    private Service service;

    private Route route;

    private Consumer consumer;

    private Map<String, Object> config;

    private List<String> protocols;

    private Boolean enabled;

    private List<String> tags;

    public Plugin() {
        /**默认启用插件*/
        this.enabled = true;
    }

    private Plugin(Builder builder) {
        this.name = builder.name;
        this.consumer = builder.consumer;
        this.service = builder.service;
        this.route = builder.route;
        this.config = builder.config;
        this.enabled = true;
    }

    public static class Service {
        private String id;

        public Service() {
        }

        public Service(String id) {
            this.id = id;
        }

        public String getId() {
            return id;
        }

        public void setId(String id) {
            this.id = id;
        }

        @Override
        public String toString() {
            final StringBuilder sb = new StringBuilder("Service{");
            sb.append("id='").append(id).append('\'');
            sb.append('}');
            return sb.toString();
        }
    }

    public static class Route {
        private String id;

        public Route() {
        }

        public Route(String id) {
            this.id = id;
        }

        public String getId() {
            return id;
        }

        public void setId(String id) {
            this.id = id;
        }

        @Override
        public String toString() {
            final StringBuilder sb = new StringBuilder("Route{");
            sb.append("id='").append(id).append('\'');
            sb.append('}');
            return sb.toString();
        }
    }

    public static class Consumer {
        private String id;

        public Consumer() {
        }

        public Consumer(String id) {
            this.id = id;
        }

        public String getId() {
            return id;
        }

        public void setId(String id) {
            this.id = id;
        }

        @Override
        public String toString() {
            final StringBuilder sb = new StringBuilder("Consumer{");
            sb.append("id='").append(id).append('\'');
            sb.append('}');
            return sb.toString();
        }
    }

    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public Date getCreatedAt() {
        return createdAt;
    }

    public void setCreatedAt(Date createdAt) {
        this.createdAt = createdAt;
    }

    public Service getService() {
        return service;
    }

    public void setService(Service service) {
        this.service = service;
    }

    public Route getRoute() {
        return route;
    }

    public void setRoute(Route route) {
        this.route = route;
    }

    public Consumer getConsumer() {
        return consumer;
    }

    public void setConsumer(Consumer consumer) {
        this.consumer = consumer;
    }

    public Map<String, Object> getConfig() {
        return config;
    }

    public void setConfig(Map<String, Object> config) {
        this.config = config;
    }

    public List<String> getProtocols() {
        return protocols;
    }

    public void setProtocols(List<String> protocols) {
        this.protocols = protocols;
    }

    public Boolean isEnabled() {
        return enabled;
    }

    public void setEnabled(Boolean enabled) {
        this.enabled = enabled;
    }

    public List<String> getTags() {
        return tags;
    }

    public void setTags(List<String> tags) {
        this.tags = tags;
    }

    public static class Builder {
        private String name;

        private Consumer consumer;

        private Service service;

        private Route route;

        private Map<String, Object> config;

        public Builder(String name) {
            this.name = name;
        }

        public Builder setConsumer(Consumer consumer) {
            this.consumer = consumer;
            return this;
        }

        public Builder setService(Service service) {
            this.service = service;
            return this;
        }

        public Builder setRoute(Route route) {
            this.route = route;
            return this;
        }

        public Builder setConfig(Map<String, Object> config) {
            this.config = config;
            return this;
        }

        public Plugin builder() {
            return new Plugin(this);
        }
    }

    @Override
    public String toString() {
        final StringBuilder sb = new StringBuilder("Plugin{");
        sb.append("id='").append(id).append('\'');
        sb.append(", name='").append(name).append('\'');
        sb.append(", createdAt=").append(createdAt);
        sb.append(", route='").append(route).append('\'');
        sb.append(", service='").append(service).append('\'');
        sb.append(", consumer='").append(consumer).append('\'');
        sb.append(", config=").append(config);
        sb.append(", protocols=").append(protocols);
        sb.append(", enabled=").append(enabled);
        sb.append(", tags=").append(tags);
        sb.append('}');
        return sb.toString();
    }
}
